﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Pharmacy.Web.UI;
using Pharmacy.Data;
using Pharmacy.Entities;


public partial class Admin_Default : System.Web.UI.Page
{
    private int DeletedRow = 0;
    private string Text = "";
    protected void Page_Load(object sender, EventArgs e)
    {

        FormUtil.RedirectAfterUpdate(GridView1, "Prescription.aspx?page={0}");
        FormUtil.SetPageIndex(GridView1, "page");
        FormUtil.SetDefaultButton((Button)GridViewSearchPanel1.FindControl("cmdSearch"));
        PrescriptionDetail objPre = DataRepository.PrescriptionDetailProvider.GetAll()[0];
        decimal Amount = objPre.AmountPrice;

        Response.Write(DeletedRow);
    }

    protected override void OnInitComplete(EventArgs e)
    {
        base.OnInitComplete(e);
        Text = Button1.Text;
        //foreach (GridViewRow row in GridView1.Rows)
        //{
        //    if (row.Cells[4].Text == "Deleted")
        //        DeletedRow++;
        //}
    }
    protected override void RaisePostBackEvent(IPostBackEventHandler sourceControl, string eventArgument)
    {
        Text = Button1.Text;
        base.RaisePostBackEvent(sourceControl, eventArgument);
        Text = Button1.Text;
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        string prescriptionID = e.CommandArgument.ToString().Trim();
        if (e.CommandName == "CustomDelete")
        {
            TList<Pharmacy.Entities.PrescriptionDetail> objPrescriptionDetail = DataRepository.PrescriptionDetailProvider.GetByPrescriptionId(prescriptionID);
            if (objPrescriptionDetail.Count > 0)
            {
                Response.Write(@"<script language='javascript'>alert('Vui lòng xóa tất cả chi tiết.')</script>");

            }
            else
            {
                Pharmacy.Entities.Prescription objPrescription = new Pharmacy.Entities.Prescription();
                objPrescription.PrescriptionId = prescriptionID;
                DataRepository.PrescriptionProvider.Delete(objPrescription);
            }
            //  GridView1.DataBind();
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in GridView1.Rows)
        {
            HiddenField control = (HiddenField)row.FindControl("TestHF");

        }
    }

}
